
// MOST basic vl
vl = {}
vl.Vec2D = function(x,y) {
	this.x = 0;
	this.y = 0;
	if(x != null) this.x = x; if(y != null) this.y = y;
}
vl.Vec2D.prototype.clone = function(other) { return new vl.Vec2D(this.x,this.y); }
vl.Vec2D.prototype.set = function(x,y) { if(x != null) this.x = x; if(y != null) this.y = y; }
vl.Vec2D.prototype.add = function(other) { this.x += other.x; this.y += other.y; }
vl.Vec2D.prototype.sub = function(other) {
	this.x -= other.x; this.y -= other.y;
	}
vl.Vec2D.prototype.mul = function(s) { this.x *= s; this.y *= s; }
vl.Vec2D.prototype.div = function(s) { this.x /= s; this.y /= s; }
vl.Vec2D.prototype.cross = function(o){ return this.x * o.y - this.y * o.x }
vl.Vec2D.prototype.cross = function(o){ return this.x * o.x + this.y * o.y }

vl.Vec2D.prototype.length = function() { return Math.floor(Math.sqrt(this.x*this.x + this.y*this.y) + 0.5); }
vl.Vec2D.prototype.normalize = function(s) { 
	var mag = this.length();
	if(mag > 0) {
		this.x = this.x / mag;
		this.y = this.y / mag;
	}
	if(Math.abs(this.x) < 0.0000001) this.x = 0;
	if(Math.abs(this.y) < 0.0000001) this.y = 0;
}
vl.Vec2D.prototype.angle = function(o) { 
	var angle = Math.acos(this.dot(o)/(this.length()*o.length())) * (180/Math.PI) // degrees
	if(this.y < o.y) angle = angle * -1;
	return angle;
}


	
vl.Rect2D = function(x,y,width,height) {
	this.x = 0;
	this.y = 0;
	this.width = 0;
	this.height = 0;
	if(x != null) this.x = x; if(y != null) this.y = y;
	if(width != null) this.width = width; if(height != null) this.height = height;
}
vl.Rect2D.prototype.set = function(x,y,width,height) {
	if(x != null) this.x = x; if(y != null) this.y = y;
	if(width != null) this.width = width; if(height != null) this.height = height;
}
vl.Rect2D.prototype.inside = function(p) {
	var inside = false;
	if(p.x >= this.x && p.x <= this.x + this.width && p.y >= this.y && p.y <= this.y + this.height) {
		inside = true;
	}
	return inside;
}
vl.Rect2D.prototype.overlaps = function(other) {
	var overlap = false;
	var x1 = 1;
	var y1 = 1;
	var x2 = 1;
	var y2 = 1;

	if(other.x < this.x) x1 = 0;
	else if(other.x > this.x + this.width) x1 = 2;

	if(other.y < this.y) y1 = 0
	else if(other.y > this.y + this.height) y1 = 2;

	if(x1 == 1 && y1 == 1) return true;

	if(other.x + other.width < this.x) x2 = 0;
	else if(other.x + other.width > this.x + this.width) x2 = 2;

	if(other.y + other.height < this.y) y2 = 0;
	else if(other.y + other.height  > this.y + this.height) y2 = 2;

	if((x1 != 1 && x2 == x1) || (y1 != 1 && y2 == y1)) return false;
	else return true;
}
